package servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import bean.DbBean;
import bean.userBean;

/**
 * Servlet implementation class updateUsersvl
 */
@WebServlet("/updateUsersvl")
public class updateUsersvl extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public updateUsersvl() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		this.doPost(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		DbBean db = new DbBean();
		request.setCharacterEncoding("utf-8");
		response.setCharacterEncoding("utf-8");
		HttpSession session = request.getSession();	
		int id = (int)session.getAttribute("userId");
		userBean ub = new userBean();
		String username = request.getParameter("nm");
		String nickname = request.getParameter("nicknm");
		String password = request.getParameter("psw");
		String password1 = request.getParameter("psw1");
		if(!password.equals(password1)){
			request.getRequestDispatcher("userInfosvl").forward(request, response);
		}else{
			if(ub.updateUser(id, username, password1, nickname)){
				request.getRequestDispatcher("indexsvl").forward(request, response);
			}else{
				request.getRequestDispatcher("userInfosvl").forward(request, response);
			}
		}
	}
	}


